package com.xquant.common.engine.xPP.cxf;


import com.xquant.common.engine.xPP.cxf.webservice.NotifyParam;
import com.xquant.common.engine.xPP.entity.NotifyParamL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class NotifyDataFacade {


    @Autowired
    private XQuantPPService xQuantPPService;

    /**
     * 通知金融工具
     */
    public void notifyInstrument(NotifyParamL paramL) {
        NotifyParam notifyParam = converToNotifyParam(paramL);
        notifyParam.setDataType(0);

        xQuantPPService.notifyData(notifyParam);
    }

    /**
     * 定息数据通知
     */
    public void notifyFixingData(NotifyParamL paramL) {
        NotifyParam notifyParam = converToNotifyParam(paramL);
        notifyParam.setDataType(1);

        xQuantPPService.notifyData(notifyParam);
    }

    /**
     * 金融工具关系变化通知
     */
    public void notifyInstrumentrelation(NotifyParamL paramL) {
        NotifyParam notifyParam = converToNotifyParam(paramL);
        notifyParam.setDataType(2);

        xQuantPPService.notifyData(notifyParam);
    }

    /**
     * 交易日历变化通知
     */
    public void notifyCalendar(NotifyParamL paramL) {
        NotifyParam notifyParam = converToNotifyParam(paramL);
        notifyParam.setDataType(3);

        xQuantPPService.notifyData(notifyParam);
    }

    /**
     * 曲线、期限结构变化通知
     */
    public void notifyYieldCurveTS() {
        NotifyParam notifyParam = new NotifyParam();
        notifyParam.setDataType(4);
        notifyParam.setIsAll(true);
        xQuantPPService.notifyData(notifyParam);
    }

    /**
     * 定价环境变化通知
     */
    public void notifyPrcingEnv(NotifyParamL paramL) {
        NotifyParam notifyParam = converToNotifyParam(paramL);
        notifyParam.setDataType(5);
        xQuantPPService.notifyData(notifyParam);
    }

    /**
     * 行情集变化通知
     */
    public void notifyDailySet(NotifyParamL paramL) {
        NotifyParam notifyParam = converToNotifyParam(paramL);
        notifyParam.setDataType(6);
        xQuantPPService.notifyData(notifyParam);
    }

    /**
     * 行情集变化通知
     */
    public void notifyDailySet() {
        NotifyParamL paramL = new NotifyParamL();
        paramL.setIsAll("true");
        notifyDailySet(paramL);
    }

    /**
     * 启动通知
     */
    public void notifyStart() {
        NotifyParam notifyParam = new NotifyParam();
        notifyParam.setDataType(7);
        xQuantPPService.notifyData(notifyParam);
    }

    /**
     * 停止通知
     */
    public void notifyStop() {
        NotifyParam notifyParam = new NotifyParam();
        notifyParam.setDataType(8);
        xQuantPPService.notifyData(notifyParam);
    }

    /**
     * 表变化通知
     */
    public void notifyTable(NotifyParamL paramL) {
        NotifyParam notifyParam = converToNotifyParam(paramL);
        notifyParam.setDataType(9);
        xQuantPPService.notifyData(notifyParam);
    }

    /**
     * 波动率曲面、期限结构变化通知
     */
    public void notifyVolSurfaceTS(NotifyParamL paramL) {
        NotifyParam notifyParam = converToNotifyParam(paramL);
        notifyParam.setDataType(10);
        xQuantPPService.notifyData(notifyParam);
    }

    /**
     * 波动率曲面、期限结构变化通知
     */
    public void notifyVolSurfaceTS() {
        NotifyParamL paramL = new NotifyParamL();
        paramL.setIsAll("true");
        notifyVolSurfaceTS(paramL);
    }

    /**
     * 批量加载金融工具通知
     */
    public void notifyBatchLoadInstrument(NotifyParamL paramL) {
        NotifyParam notifyParam = converToNotifyParam(paramL);
        notifyParam.setDataType(11);
        xQuantPPService.notifyData(notifyParam);
    }

    /**
     * 红利曲线、期限结构变化通知
     */
    public void notifyDivYieldCurveTS(NotifyParamL paramL) {
        NotifyParam notifyParam = converToNotifyParam(paramL);
        notifyParam.setDataType(12);
        xQuantPPService.notifyData(notifyParam);
    }

    /**
     * 红利曲线、期限结构变化通知
     */
    public void notifyDivYieldCurveTS() {
        NotifyParamL paramL = new NotifyParamL();
        paramL.setIsAll("true");
        notifyDivYieldCurveTS(paramL);
    }

    /**
     * 观察数据通知
     */
    public void notifyObserveData(NotifyParamL paramL) {
        NotifyParam notifyParam = converToNotifyParam(paramL);
        notifyParam.setDataType(13);
        xQuantPPService.notifyData(notifyParam);
    }

    /**
     * 利差数据通知
     */
    public void notifySpreadData(NotifyParamL paramL) {
        NotifyParam notifyParam = converToNotifyParam(paramL);
        notifyParam.setDataType(14);
        xQuantPPService.notifyData(notifyParam);
    }

    /**
     * 重启通知
     */
    public void notifyRestart(NotifyParamL paramL) {
        NotifyParam notifyParam = converToNotifyParam(paramL);
        notifyParam.setDataType(15);
        xQuantPPService.notifyData(notifyParam);
    }

    /**
     * 相关系数通知
     */
    public void notifyCorrData(NotifyParamL paramL) {
        NotifyParam notifyParam = converToNotifyParam(paramL);
        notifyParam.setDataType(16);
        xQuantPPService.notifyData(notifyParam);
    }

    /**
     * 远期价格通知
     */
    public void notifyForwardPriceCurveTS(NotifyParamL paramL) {
        NotifyParam notifyParam = converToNotifyParam(paramL);
        notifyParam.setDataType(17);
        notifyParam.setIsAll(true);
        xQuantPPService.notifyData(notifyParam);
    }

    /**
     * 违约利率曲线、期限结构变化通知
     */
    public void notifyDefYieldCurveTS(NotifyParamL paramL) {
        NotifyParam notifyParam = converToNotifyParam(paramL);
        notifyParam.setDataType(18);
        xQuantPPService.notifyData(notifyParam);
    }

    /**
     * 违约利率曲线期限结构变化通知
     */
    public void notifyDefYieldCurveTS() {
        NotifyParamL paramL = new NotifyParamL();
        paramL.setIsAll("true");
        notifyDefYieldCurveTS(paramL);
    }

    /**
     * 分红数据通知
     */
    public void notifyDividendData(NotifyParamL paramL) {
        NotifyParam notifyParam = converToNotifyParam(paramL);
        notifyParam.setDataType(19);
        xQuantPPService.notifyData(notifyParam);
    }

    /**
     * 分红数据通知
     */
    public void notifyDividendData() {
        NotifyParamL paramL = new NotifyParamL();
        paramL.setIsAll("true");
        notifyDividendData(paramL);
    }

    /**
     * 评级数据通知
     */
    public void notifyRatingData(NotifyParamL paramL) {
        NotifyParam notifyParam = converToNotifyParam(paramL);
        notifyParam.setDataType(20);
        xQuantPPService.notifyData(notifyParam);
    }

    /**
     * 净值数据刷新(基金)通知
     */
    public void notifyNavData(NotifyParamL paramL) {
        NotifyParam notifyParam = converToNotifyParam(paramL);
        notifyParam.setDataType(21);
        xQuantPPService.notifyData(notifyParam);
    }

    /**
     * 风险因子收益率数据通知
     */
    public void notifyRFYieldData(NotifyParamL paramL) {
        NotifyParam notifyParam = converToNotifyParam(paramL);
        notifyParam.setDataType(22);
        xQuantPPService.notifyData(notifyParam);
    }

    private NotifyParam converToNotifyParam(NotifyParamL paramL) {

        NotifyParam param = new NotifyParam();
        param.setDataID(paramL.getDataID());
        param.setDate(paramL.getDate());
        param.setIsAll(paramL.getIsAll() == null ? false : Boolean.valueOf(paramL.getIsAll()));
        param.setChangeType(paramL.getChangeType());
        param.setEncoding(paramL.getEncoding());
        return param;
    }

}
